package com.itheima.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.itheima.constant.MessageConstant;
import com.itheima.entity.Result;
import com.itheima.pojo.Setmeal;
import com.itheima.service.SetMealService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/setmeal")
public class SetmealController {

    //注入service
    @Reference
    private SetMealService setMealService;

    /*
        获取套餐列表
     */
    @RequestMapping("/getSetmeal")
    public Result getSetMeal() {
        try {
            //调用服务层,查询套餐列表
            List<Setmeal> setMealList = setMealService.findAllSetMeals();
            return new Result(true, MessageConstant.GET_SETMEAL_LIST_SUCCESS, setMealList);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, MessageConstant.GET_SETMEAL_LIST_FAIL);
        }
    }

    /*
        根据套餐id查询套餐列表,检查组信息,以及检查组中包含的检查项信息
     */
    @RequestMapping("/findSetMealById")
    public Result findSetMealById(int id) {
        try {
            //调用服务层,查询套餐列表
            Setmeal setMeal = setMealService.findSetMealById(id);
            return new Result(true, MessageConstant.QUERY_SETMEAL_SUCCESS, setMeal);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, MessageConstant.QUERY_SETMEAL_FAIL);
        }
    }
}
